<?php $this->pageHeader('Rediger profil'); ?>

<?php echo $this->flashMessage()->renderMessages();

if($this->personaliaMessage) {
    echo $this->personaliaMessage;
} else if($this->phoneMessage) {
    echo $this->phoneMessage;
} else if($this->emailMessage) {
    echo $this->emailMessage;
} else if($this->nextOfKinMessage) {
    echo $this->nextOfKinMessage;
}
?>

<div>
<h2>Synlighet</h2>
<?php echo $this->privacyForm; ?>
</div>
<p>&nbsp;</p>

<div>
<h2>Personalia</h2>
<?php echo $this->personalInfoForm; ?>
</div>
<p>&nbsp;</p>

<div>
<h2>Telefonnummer</h2>
    <table>
  <thead>
  <tr>
      <th>Telefonnummer</th>
            <th>Type</th>
            <th>&nbsp;</th>
  </tr>
  </thead>
  <tbody>
  <?php foreach($this->member->Phonenumbers as $phonenumber) { ?>
  <tr>
      <td><?php echo $phonenumber->number; ?></td>
      <td><?php echo $phonenumber->Phonetype->name; ?></td>
      <td>
    <a href="<?php echo $this->url(array('action' => 'remove-phone', 'id' => $phonenumber->id)); ?>">
    Slett
    </a>
      </td>
  </tr>
  <?php } ?>
  </tbody>
    </table>
<p>&nbsp;</p>
<?php echo $this->phoneInfoForm; ?>

</div>
<p>&nbsp;</p>
<div>
<h2>Epost adresser</h2>
    <table>
  <thead>
      <tr>
    <th>Adresse</th>
    <th>&nbsp;</th>
      </tr>
  </thead>
  <tbody>
      <?php foreach($this->member->emails as $email) { ?>
      <?php $isMainEmail = (bool)$email->is_main; ?>
      <tr>
    <td><?php echo $this->escape($email->address); ?><?php if ($isMainEmail) echo '*'; ?></td>
    <td>
    <?php if (!$isMainEmail) : ?>
        <a href="<?php echo $this->url(array('action' => 'remove-email', 'id' => $email->id)); ?>">Slett</a>
         | <a href="<?php echo $this->url(array('action' => 'set-main-email', 'id' => $email->id)); ?>">Hoved</a>
    <?php endif; ?>
      </td>

    </tr>
    <?php } ?>
  </tbody>
  </table>
<p>&nbsp;</p>
<?php echo $this->emailInfoForm; ?>
</div>

<p>&nbsp;</p>

<div>
<h2>Pårørende</h2>
<?php if (sizeof($this->member->NextOfKin) > 0): ?>
    <table>
    <thead>
        <tr>
        <th>Navn</th>
        <th>Telefonnummer</th>
        <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($this->member->NextOfKin as $NextOfKin) { ?>
        <tr>
        <td><?php echo $this->escape($NextOfKin->first_name . ' ' . $NextOfKin->last_name); ?></td>
        <td><?php echo $this->escape($NextOfKin->phone_number); ?></td>
        <td>
            <a href="<?php echo $this->url(array('action' => 'remove-next-of-kin', 'id' => $NextOfKin->id)); ?>">Slett</a>
        </td>
        </tr>
        <?php } ?>
    </tbody>
    </table>
    <?php else: ?>
        <p>Ingen pårørende registrert</p>
    <?php endif; ?>
<p>&nbsp;</p>
<?php echo $this->nextOfKinInfoForm; ?>
</div>

<p>&nbsp;</p>

<div>
<h2>Sertifikater</h2>
<?php if (sizeof($this->member->Diplomas) > 0): ?>
    <table class="core_user_edit_diplomas">
        <thead>
            <tr>
                <th>Beskrivelse</th>
                <th>Tidspunkt</th>
                <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
        <?php foreach($this->member->Diplomas as $diploma): ?>
            <?php
                $class = "";
                if (preg_match('/.*\.(jpg|jpeg|png|gif)/i', $diploma->file_name) > 0):
                    $class = "image";
                endif;
            ?>
            <tr>
                <td><?php echo $diploma->description; ?></td>
                <td><?php echo $diploma->upload_date; ?></td>
                <td>
                <a href="<?php echo $this->imageLink('uploads/'.$diploma->file_name); ?>" class="<?php echo $class; ?>">Vis</a>
                    | <a href="<?php echo $this->url(array('action' => 'remove-diploma', 'id' => $diploma->id)); ?>">Slett</a>
                </td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
<?php else: ?>
    <p>Du har ikke lastet opp noen sertifikater.</p>
<?php endif; ?>

<p>&nbsp;</p>
<?php echo $this->uploadDiplomaForm; ?>
</div>
